//
//  MTTFProfileController.m
//  ShiShiBang
//
//  Created by 宋宝强 on 16/9/24.
//  Copyright © 2016年 motianjituan. All rights reserved.
//

#import "MTTFProfileController.h"

#import "MTPersonPhotoCell.h"
#import "MTAuthenticationNewsCell.h"
#import "MTMineHeadView.h"
#import "MTLikeCell.h"
@interface MTTFProfileController ()

@end

@implementation MTTFProfileController



static NSString * const MTPersonPhotoCellID = @"MTPersonPhotoCell";
static NSString * const MTAuthenticationNewsCellID = @"MTAuthenticationNewsCell";
static NSString * const MTLikeCellID = @"MTLikeCell";
static NSString * const MTSkillID = @"MTSkillCell";
- (void)viewDidLoad {
    [super viewDidLoad];

    
    
    self.view.backgroundColor = UIColorFromRGB(0xf7f7f7);
    
    
    [self setInitialize];
    
}



//  初始化
- (void)setInitialize{
    
    // 注册cell
    [self.tableView registerNib:[UINib nibWithNibName:MTPersonPhotoCellID bundle:nil] forCellReuseIdentifier:MTPersonPhotoCellID];
    [self.tableView registerNib:[UINib nibWithNibName:MTAuthenticationNewsCellID bundle:nil] forCellReuseIdentifier:MTAuthenticationNewsCellID];
    [self.tableView registerNib:[UINib nibWithNibName:MTLikeCellID bundle:nil] forCellReuseIdentifier:MTLikeCellID];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:MTSkillID];
    MTMineHeadView *headView = [MTMineHeadView loadxib];
    [headView.backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    headView.mt_height = 267;
    
    self.tableView.tableHeaderView = headView;
    
    self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);
    self.tableView.sectionFooterHeight = 0;
    self.tableView.sectionHeaderHeight = 14;

}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}



- (instancetype)init{
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        
    }
    return self;
}

- (instancetype)initWithStyle:(UITableViewStyle)style{
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        
    }
    return self;
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if(section == 0) return 3;
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    MTPersonPhotoCell *photoCell = [tableView dequeueReusableCellWithIdentifier:MTPersonPhotoCellID];
    MTAuthenticationNewsCell *newsCell = [tableView dequeueReusableCellWithIdentifier:MTAuthenticationNewsCellID];
    MTLikeCell *likecell = [tableView dequeueReusableCellWithIdentifier:MTLikeCellID];
    UITableViewCell *skillCell = [tableView dequeueReusableCellWithIdentifier:MTSkillID];
    skillCell.textLabel.text = @"发布的技能";
    skillCell.textLabel.textColor = UIColorFromRGB(0x555555);
    skillCell.textLabel.font = [UIFont systemFontOfSize:16];
 
            switch (indexPath.section) {
                case 0:
                    switch (indexPath.row) {
                        case 0:
                        {
                           return photoCell;
                        }
                           break;
                        case 1:
                        {
                            return newsCell;
                        }
                            break;
                        case 2:
                        {
                            return likecell;
                        }
                            break;
                        default:
                            break;
                    }
                    break;
                    
                default:
                    switch (indexPath.row) {
                        case 0:
                        {
                            return skillCell;
                        }
                            break;
                            
                        default:
                            break;
                    }
                    break;
            }
    return likecell;
}

#pragma mark - UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    if ([cell isKindOfClass:[MTPersonPhotoCell class]]) {
        MTPersonPhotoCell *photoCell = (MTPersonPhotoCell *)cell;
        return photoCell.cellHeight;
    }else if ([cell isKindOfClass:[MTAuthenticationNewsCell class]]){
        MTAuthenticationNewsCell *newsCell = (MTAuthenticationNewsCell *)cell;
        return newsCell.cellHeight;
    }else if ([cell isKindOfClass:[MTLikeCell class]]){
        MTLikeCell *likeCell = (MTLikeCell *)cell;
        return likeCell.cellHeight;
    } else {
        return 44;
    }

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

-(void)backBtnClick {
    [self.navigationController popViewControllerAnimated:YES];
}
@end
